<?php

	header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

	require("frmCookie.php");
	
	$iOpcion = $_GET[iOpcion];
?>
<html>
	<head>
    	<?php
		require("frmHeader.php");
		?>
		<script language="javascript" src="scripts/ajax.js"></script>
		<script language="javascript" src="scripts/validar.js"></script>
	</head>
	<body>
    	<table cellpadding="0" cellspacing="0" align="center" class="tablaPrincipal">
        	<tr>
            	<td align="center">
                	<?php
					require("frmSession.php"); 
					
					//Redirecciona a SINPERMISOS.PHP en caso de no tener permisos
					switch ($iOpcion)
					{
						case 1:
						case 2:
						{
							
							if (!(in_array(13001, $_SESSION[permisos])))
							{
							?>
							  <script language="JavaScript" type="text/javascript">
							  <!--
							  window.location.href = "sinPermisos.php"
							  //-->
							  </script>
							<?php
							}
							$titulo = "Reporte de Ventas";
							break;
						}
					}
					
					?>
                </td>
            </tr>
            <tr>
            	<td align="center">
                	<?php
					require("frmTitulo.php");
					?>
                </td>
            </tr>
            <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
            	<td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="menuPrincipal">
                    	<tr>
                        	<td>
								<?php
                                require("frmMenu.php");
                                ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
                <td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="tituloPantalla">
                    	<tr>
                        	<td align="center">
                            	<p class="texto" align="left"><?php echo $titulo; ?></p>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
             <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
                <td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="estadoPantalla">
                    	<tr>
                        	<td align="center">
                            	<p class="texto" align="left"><?php echo $mensaje; ?></p>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
             <tr>
            	<td height="20">&nbsp;
                	
                </td>
            </tr>
            <tr>
                <td align="center">
                	<table cellpadding="0" cellspacing="0" align="center" class="contenedorPrincipal">
                    	<tr>
                        	<td align="">
                        		<?php
                        		switch($iOpcion)
                        		{
                        			case 1:
                        			{
                				?>
                				<table>
                        			<tr>
                        				<th class="listaHead">Nro de Factura</th>
       									<th class="listaHead">Cantidad de Items</th>
                        			</tr>
                        			<?php
                        			$mySQL = "SELECT nroFactura, SUM(cantidad) AS CANTIDAD FROM ventas GROUP BY nroFactura";
                        			$result = readSQL($mySQL);

									$i = 0;			    							
	  				                foreach($result as $value)
	  				                {
	  				                	if($i%2==0)
	  				                		$class = "par";
	  				                	else
	  				                		$class = "impar";
				                	?>
				                	<tr>
				                		<td class="<?php echo $class; ?>" align="right"><a class="listaHeadLink" href="reporteVentas.php?iOpcion=2&nroFactura=<?php echo $value['nroFactura']; ?>"><?php echo $value['nroFactura']; ?></td>
				                		<td class="<?php echo $class; ?>" align="right"><?php echo $value['CANTIDAD']; ?></td>
				                	</tr>
				                	<?php
				                		$i++;
	  				                }
                        			?>
                        		</table>
                				<?php
                        				break;
                        			}
                        			case 2:
                        			{
								?>
								<table>
                        			<tr>
                        				<td>Nro de Factura: <b><?php echo $_GET[nroFactura]; ?></b></td>
                        			</tr>
                        			<tr>
                        				<td>
                        					<table>
	                        					<tr>
			                        				<th class="listaHead">Codigo Tango</th>
			                        				<th class="listaHead">Parte</th>
			                        				<th class="listaHead">Imei</th>
			       									<th class="listaHead">Cantidad</th>
			                        			</tr>
			                        			<?php
			                        			$mySQL = "SELECT P.codigoTango, P.descripcionInterna, V.imei, V.cantidad, V.imei FROM ventas V, partes P WHERE P.idParte = V.idParte AND V.nroFactura='" . $_GET[nroFactura] . "'";
			                        			$result = readSQL($mySQL);
			
												$i = 0;			    							
				  				                foreach($result as $value)
				  				                {
				  				                	if($i%2==0)
				  				                		$class = "par";
				  				                	else
				  				                		$class = "impar";
							                	?>
							                	<tr>
							                		<td class="<?php echo $class; ?>" align="right"><?php echo $value['codigoTango']; ?></td>
							                		<td class="<?php echo $class; ?>" align="left"><?php echo $value['descripcionInterna']; ?></td>
							                		<td class="<?php echo $class; ?>" align="left"><?php echo $value['imei']; ?></td>
							                		<td class="<?php echo $class; ?>" align="right"><?php echo $value['cantidad']; ?></td>
							                	</tr>
							                	<?php
							                		$i++;
				  				                }
			                        			?>
                        					</table>
                        				</td>
                        			</tr>
                        		</table>
								<?php                        				
                        				break;
                        			}
                        		}
                        		?>
                        	</td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
	</body>
</html>